package ${package.Controller};


import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>


/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
* @version v1.0
*/
<#if restControllerStyle>
@Api(tags = {"${table.comment!}"})
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};


    /**
    * 新增数据
    *
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation(value = "新增数据", notes = "新增一条${table.comment!}数据")
    @PostMapping("insert")
    public Long insert(@RequestBody ${entity}VO ${entity?uncap_first}) {
        return ${(table.serviceName?substring(1))?uncap_first}.insert(${entity?uncap_first});
    }

    /**
    * 修改数据
    *
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation(value = "修改数据", notes = "根据id修改${table.comment!}数据")
    @PostMapping("update")
    public int update(@RequestBody ${entity}VO ${entity?uncap_first}) {
        return ${(table.serviceName?substring(1))?uncap_first}.update(${entity?uncap_first});
    }

    /**
    * 删除数据
    *
    * @param ids
    * @return
    */
    @ApiOperation(value = "删除数据", notes = "根据id删除${table.comment!}数据")
    @PostMapping("delete")
    public int delete(@RequestBody Long[] ids) {
        return ${(table.serviceName?substring(1))?uncap_first}.deleteLogicByIds(ids);
    }

    /**
    * 根据ID查询数据
    *
    * @param id
    * @return
    */
    @ApiOperation(value = "根据ID查询数据", notes = "根据ID查询${table.comment!}数据")
    @GetMapping("detail")
    public ${entity}DTO detail(@RequestParam("id") Long id) {
        return ${(table.serviceName?substring(1))?uncap_first}.getDtoById(id);
    }

    /**
    * 查询分页数据
    */
    @ApiOperation(value = "查询${table.comment!}分页数据")
    @GetMapping(value = "list")
    public Pagination<${entity}DTO> list(RequestPage requestPage,Long ownerId){
        return ${(table.serviceName?substring(1))?uncap_first}.query(requestPage,ownerId);
    }
}
</#if>